package com.yaoli.ZuoChengYun;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * Created by YaoLi on 2017/8/28.
 *
 * 最长公共子序列
 *
 */
public class ZuiChangGongGongZiXuLie {

    public static void main(String[] args) {
        Scanner ninput = new Scanner(System.in);
        int n = ninput.nextInt();
        List<String> list = new ArrayList<>();



        while(list.size() != n){
            String temp = ninput.nextLine();
            if(!"".equals(temp)){
                list.add(temp);
            }
        }

        for(int i = 0 ; i < list.size() ; i++){
            String [] lines = list.get(i).split(" ");
            for(int j = lines.length - 1 ; j >= 0 ; j--){
                if(j == 0){
                    System.out.print(lines[j]);
                }else{
                    System.out.print(lines[j]+" ");
                }
            }
            System.out.println();
        }


//        Scanner input = new Scanner(System.in);
//
//        while(input.hasNext()){
//            long a = input.nextLong();
//            long b = input.nextLong();
//
//            System.out.println(a+b);
//        }
//        String a = "A1BC2";
//        String b = "AB34C";
//        int [][] c = getDp(a.toCharArray(),b.toCharArray());
//        System.out.println("");

    }


    public static int [][] getDp(char [] str1,char [] str2){
        int [][] dp = new int[str1.length][str2.length];
        dp[0][0] = str1[0] == str2[0] ? 1 : 0;
        //循环，依次比较str1的第i个字符 与 str2的第一个字符
        for (int i = 1; i < str1.length; i++) {
            dp[i][0] = Math.max(dp[i-1][0], str1[i] == str2[0] ? 1 : 0);
        }
        //同上
        for (int j = 1; j < str2.length; j++) {
            dp[0][j] = Math.max(dp[0][j-1], str1[0] == str2[j] ? 1 : 0);
        }
        //
        for (int i = 1 ; i < str1.length ; i++){
            for (int j = 1; j < str2.length; j++) {
                dp[i][j] = Math.max(dp[i - 1][j],dp[i][j - 1]);
                if(str1[i] == str2[j]){
                    dp[i][j] = Math.max(dp[i][j],dp[i - 1][j - 1] + 1);
                }
            }
        }

        return dp;
    }

}
